home *** CD-ROM | disk | FTP | other *** search
- /* bar.c */
- /* Entered by A. Wayner */
-
- # include <graphics.h>
- # include <stdlib.h>
-
- main()
- {
- int graphdriver = DETECT;
- int graphmode, i;
- int data[5] = {2, 1, 3, 5, 4 }, maxdata = 5, numpt = 5;
- int maxheight, maxwidth, xstep, ystep, x, y, maxcolor;
-
-
- /* Detect adapter type and */
- /* initialize graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc");
- outtextxy( 10, 10, "Bar graphs using 'bar' ");
-
- /* Now draw the bar graph */
- maxheight = getmaxy() - 100;
- ystep = maxheight / maxdata;
-
- maxwidth = getmaxx() - 200;
- xstep = maxwidth / numpt;
-
- x = 100;
- y = maxheight + 40;
-
- /* Use random color */
- randomize();
- maxcolor = getmaxcolor();
- for( i = 0; i < numpt; i++, x += xstep )
- {
- setfillstyle( (i % 11) + 1, random( maxcolor ) );
- bar( x, y - data[i] * ystep, x + xstep, y );
- }
- /* Wait until user presses a key */
- outtextxy( 10, getmaxy() - 30," Press any key to exit");
-
-
- getch(); /* Wait until a key is pressed */
- closegraph(); /* Exit graphics library */
-
- }